﻿using System;
using ExcelDna.Integration;
using System.Text.RegularExpressions;
//using System.Windows.Forms;
using System.Threading;
namespace excelUDF
{
    public class excelUdfOfPP
    {
        [ExcelFunction(Description = "正则表达式匹配单元格\n规则为空，返回Null;找到返回单元格内容；找不到，返回空字符串。", Category = "PP's Useful functions")]
        public static object CellReMatch(string pattenCell, string input)
        {
            //MessageBox.Show(pattenCell);
            //    MessageBox.Show(input);
            if (pattenCell.Length==0)
            {
                return ExcelDna.Integration.ExcelError.ExcelErrorNull;
                
            }
            
            Regex re = new Regex(pattenCell);

            bool matchIt = false;
            try
            {
                matchIt = re.IsMatch(input);
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
            if (matchIt)
            {
                
                return input;
            }
            else
            {
                return "";
            }

        }
        

       
    }
}
